/**
 * Created by duqunxing on 2017/1/4.
 */
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {Components} from '../constants/constants';
declare var $: any;

@Component({
  templateUrl: './page-not-found.component.html'
})
export class PageNotFoundComponent implements OnInit {
  time : number = 5;
  constructor(private router: Router) {
  }

  ngOnInit() {
    this.turn();
    this.keyDown();
  }

  turn() {
    let turnInterval = setInterval(() =>{
      this.time--;
      if (this.time == 0) {
        clearInterval(turnInterval);
        this.redirect();
      }
    }, 1000);
  }

  private keyDown(){
    $("body").keydown((e:any)=>{
      if(e.keyCode == '13'){
        this.redirect();
      }
    });
  }
  redirect() {
    this.router.navigate([Components.entryComponent]);
  }
}
